/<template>
  <div class="content">
    <el-form
      :inline="true"
      :model="formData"
      class="demo-form-inline"
    >
      <el-form-item label="观看时间">
        <BiDatePicker
          v-model="formData.viewTime"
          :clearable="false"
          style="width:280px;"
          size="small"
          type="daterange"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @change="onSearchChang"
        />
        <!-- :default-time="['00:00:00', '23:59:59']" -->
      </el-form-item>
      <el-form-item label="观看视频">
        <el-select
          ref="select"
          v-model="formData.playlet_id"
          filterable
          multiple
          collapse-tags
          remote
          reserve-keyword
          placeholder="请输入关键词"
          :remote-method="remoteMethod"
          size="small"
          clearable
          @focus="mobileClear"
          @hook:mounted="mobileClear"
          @visible-change="mobileClear"
          @change="onSearchChang"
        >
          <el-option
            v-for="item in optionsList.commonDataList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          > </el-option>
        </el-select>
        <!-- :default-time="['00:00:00', '23:59:59']" -->
      </el-form-item>

      <el-form-item>
        <el-button
          :loading="loading"
          type="primary"
          style="margin-left:10px;"
          @click="startSearch"
        >查询</el-button>
      </el-form-item>
    </el-form>
    <div class="table-table">
      <BiTable
        :loading="loading"
        :data="tableData"
        size="medium"
        :column="tableColums"
        fixed="sticky"
        fixed-offset="50"
        pagination
        layout="total, prev, pager, next"
        :auto-scroll="false"
        :total="page_info.total"
        :page.sync="page_info.page"
        :limit.sync="page_info.page_size"
        @pagination="handlePageChange"
      >
        <template v-slot:view_duration="{ row }">
          <div class="colorStatus">
            {{ row.view_duration }}s
          </div>
        </template>
      </BiTable>
    </div>
  </div>
</template>

<script>
import moment from 'moment'
import { memberView } from '@/api/userPage'
import { commonData } from '@/api/common'
export default {
  props: ['rowInfo'],
  data() {
    return {
      loading: false,
      formData: {
        viewTime: [],
        playlet_id: ''
      },
      page_info: {
        page: 1,
        page_size: 20,
        total: 0
      },
      optionsList: {
        commonDataList: []
      },
      tableData: [],
      tableColums: [
        {
          label: '观看时间',
          prop: 'view_time'
        },
        {
          label: '播放时长',
          prop: 'view_duration',
          slotScope: true
        },
        {
          label: '短剧名称',
          prop: 'playet_name'
        },
        {
          label: '剧集名称',
          prop: 'playet_chapter'
        }
      ]
    }
  },
  mounted() {
    this.formData.viewTime = [moment().subtract(1, 'days').format('YYYY-MM-DD'), moment().format('YYYY-MM-DD')]
    console.log(this.rowInfo)
    this.startSearch()
  },
  methods: {
    onSearchChang() {
      this.page_info.page = 1
    },
    async remoteMethod(query) {
      const res = await commonData({
        type: 'playlet',
        value: query
      })
      if (res.status_code == 1) {
        this.optionsList.commonDataList = res.data.data
      }
    },
    // 执行这个重新获取焦点的方法 就可以了
    mobileClear(async) {
      this.$nextTick(() => {
        if (!async) {
          // ios 手机有延迟问题
          setTimeout(() => {
            const { select } = this.$refs
            const input = select.$el.querySelector('.el-input__inner')
            input.removeAttribute('readonly')
          }, 200)
        }
      })
    },
    async startSearch() {
      const data = JSON.parse(JSON.stringify(this.formData))
      console.log(data)
      this.loading = true
      const params = {
        playlet_id: data.playlet_id,
        start_date: data.viewTime ? data.viewTime[0] : '',
        end_date: data.viewTime ? data.viewTime[1] : '',
        member_id: this.rowInfo.member_id,
        page: this.page_info.page,
        page_size: this.page_info.page_size
      }
      const res = await memberView(params)
      if (res.status_code === 1) {
        this.tableData = res.data.data
        this.page_info = res.data.page_info
      }
      this.loading = false
    },
    handlePageChange(page) {
      this.startSearch()
    }
  }
}
</script>

<style lang="scss" scoped>
.viewduration {
  display: flex;
  align-items: center;
}
</style>